unit ec_labelbase;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons,
  StdCtrls, ec_base;

type

  { TECLabelBaseFrame }

  TECLabelBaseFrame = class(TECBaseFrame)
    LabelNameEdit: TEdit;
    LabelNameLabel: TLabel;
    procedure FormShow(Sender: TObject);
  public
    function GetCommandCode: Integer; virtual;
    procedure InitExisting; override;
    procedure MakeResultingCommand; override;
  end;

var
  ECLabelBaseFrame: TECLabelBaseFrame;

implementation

uses
  fpjson;

{$R *.lfm}

{ TECLabelBaseFrame }

procedure TECLabelBaseFrame.FormShow(Sender: TObject);
begin
  LabelNameEdit.SetFocus;
end;

function TECLabelBaseFrame.GetCommandCode: Integer;
begin
  GetCommandCode := 0;
  raise ENotImplemented.Create('Called GetCommandCode of TECLabelBaseFrame');
end;

procedure TECLabelBaseFrame.InitExisting;
var
  Params: TJSONArray = nil;
  LabelName: String = '';
begin
  Params := GetFirstParams;

  if (Params <> nil) and (Params.Count >= 1) and (Params[0].JSONType = jtString)
  then
      LabelName := Params[0].AsString;

  LabelNameEdit.Text := LabelName;
end;

procedure TECLabelBaseFrame.MakeResultingCommand;
begin
  ResultingCommand := SingleLineResultingCommand(
    GetCommandCode,
    TJSONArray.Create([
      LabelNameEdit.Text
    ])
  );
end;

end.

